package servlet.manage;

import com.google.gson.Gson;
import data.Insert;
import data.Select;
import servlet.Control;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@WebServlet(name = "SelectAllProfile",value = "/manage/selectAllProfile")
public class SelectAllProfile extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page=request.getParameter("page");
        try {
            int p= Integer.parseInt(page);
            List list=Select.profilesCard(p);

            HashMap map=new HashMap<>();
            map.put("page",page);
            map.put("number",Select.profilesCount());
            map.put("data",list);

            String json=new Gson().toJson(map);

            Control.sendJson(response,json);
        }catch (Exception ex){
            ex.printStackTrace();
            Control.fail(response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
